package utils

import (
	"math/rand"
	"strconv"
	"time"
	"bytes"
)

// GetRand 获取随机数
// inInt 获取随机数在 0 - intInt 之间
var ra = rand.New(rand.NewSource(time.Now().UnixNano()))

func GetIntnRand(inInt int) int {
	return ra.Intn(inInt)
}

// GetRandWithLen 获取 指定长度的随机数
// len 要返回的长度
func GetRandWithLen(len int) (randStr string) {
	for i := 0; i < len; i++ {
		randStr += strconv.Itoa(GetIntnRand(10))
	}
	return
}

func GetCodeByLength(len int64) string {
	str := "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
	bytes1 := []byte(str)
	result := []byte{}
	r := rand.New(rand.NewSource(time.Now().UnixNano()))
	var i int64
	for i = 0; i < len; i++ {
		result = append(result, bytes1[r.Intn(bytes.Count(bytes1, nil)-1)])
	}
	return string(result)
}